Everything Totally Explained


Ask & we'll explain, totally!
Floor and ceiling functions
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


View this entry using RSS

Everything about Floor And Ceiling Functions totally explained

In mathematics and computer science, the floor and ceiling functions are two mathematical functions which convert arbitrary real numbers to close integers.
   The floor function of a real number x, denoted lfloor x floor or floor(x), is a function that returns the highest integer less than or equal to x. Formally, for all real numbers x, » lfloor x floor=max, (k) floor + 1

Some properties of the ceiling function

  • It is easy to show that: » lceil x ceil = - lfloor - x floor

  • Also: » x leq lceil x ceil < x + 1

  • For any integer k, we've the following equality: » lfloor k / 2 floor + lceil k / 2 ceil = k.

    The operator (int) in C

    C and related programming languages have a feature called type casting which allows turning a floating point value into an integer by prefixing it with (int). This operation is truncation or the round to zero method, a mixture of the floor and ceiling function: for positive or 0 x it returns floor(x), and for negative x it returns ceiling(x).
       This operation loses significant data, and can therefore magnify rounding errors with disastrous consequences. For instance, (int)(0.6/0.2) will return 2 in most implementations of C, even though 0.6/0.2 = 3. The reason is that computers work internally with the binary numeral system, and it isn't possible to represent the numbers 0.6 and 0.2 by a finite binary string. So some rounding errors occur, and the result is computed as 2.999999999999999555910790149937 which the (int) operator will convert to 2.
       Many other languages, such as Java (tested with Sun JDK version 1.5.0_05), Perl (as of version 5.8.0), and PHP (tested on version 5.2.1) behave similarly and exhibit rounding errors, as does the POSIX floor function, every time floating point types are used to store real values.
    Because of issues like these, most modern calculators use the decimal numeral system internally, but this only solves a small part of possible problems, and not the fact that (int)((4.0/9.0) * 9.0) will still return 3 instead of 4, even when using decimal floating point representation at any datatype precision (The effective result comes from the truncation of 0.44444...4444 * 9.0 = 3.99999...9996, for which either a binary or decimal internal base has no influence on the precision of the result and the error, even when correct rounding to the nearest representable number is used throughout the calculation).
       A workaround is to define an epsilon constant e (for example e = 0.00000001), and define floor(x) = (int)(x + e), and ceiling(x) = (int)(x + e) + 1, for x >= 0,
       A more elegant solution is to use better numeric datatypes to allow representing rational values exactly, or to avoid aggravating rounding errors which will only appear when non polynomial functions are used in the calculation. For example, a pair can be used for storing a floating point numerator and a positive integer divisor (a solution used in the Calculator accessory in Windows): all intermediate calculation and storage use this datatype, and the decimal floating point value is computed only for the final display of the calculator, with correct rounding up to the displayed precision.

    Computer implementations

    Practically every spreadsheet program supports some form of a ceiling function. Although the details differ between programs, most implementations support a second parameter - a multiple of which the given number is to be rounded to. As a typical example, ceiling(2, 3) would round 2 up to the nearest multiple of 3, so this would return 3. The definition of what "round up" means, however, differs from program to program. Microsoft Excel's ceiling function doesn't follow the mathematical definition, but rather as with (int) operator in C, it's a mixture of the floor and ceiling function: for x geq 0 it returns ceiling(x), and for x < 0 it returns floor(x). This has followed through to the Office Open XML file format. For example, ceiling(-4.5) returns -5.
       The OpenDocument file format, as used by OpenOffice.org and others, follows the mathematical definition of ceiling for its ceiling function, with an optional parameter for Excel compatibility. For example, ceiling(-4.5) returns -4.
       Mathematica also follows the mathematical definition.

    Truncation

    While the floor function only outputs integers, the act of real truncation, or "cutting off the digits", may be performed at any specified position, not necessarily after the units digit.

    Typesetting

    The floor and ceiling function are usually typeset with left and right square brackets where the upper (for floor function) or lower (for ceiling function) horizontal bars are missing, and, for example, in the LaTeX typesetting system these symbols can be specified with the lfloor, floor, lceil and ceil commands in math mode. Unicode contains codepoints for these symbols, at U+2308U+230B: ⌈x⌉, ⌊x⌋.

    Further Information

    Get more info on 'Floor And Ceiling Functions'.


    External Link Exchanges

    Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

      <a href="http://floor_and_ceiling_functions.totallyexplained.com">Floor and ceiling functions Totally Explained</a>

    Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
       As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



  • Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
    This article contains text from the Wikipedia article Floor and ceiling functions (History) and is released under the GFDL | RSS Version